#include "Package.h"
#include "LED.h"

//#define TEST

module ReceiveC{
	uses interface Receive;
	uses interface LEDControl;
	uses interface CC2420Packet;
	uses interface Data;
	uses interface SendFunctions;
#ifdef TEST
	uses interface ModeReceive;
#endif
}
implementation
{
	bool toggle = TRUE;
	bool test = TRUE;
	uint32_t time_value;
	char testAck[24] = "Called from receive Ack";
	char testNack[25] = "Called form receive Nack";
	Package pack;
		
	event message_t * Receive.receive(message_t * msg, void * payload, uint8_t len) 
	{	
		if(toggle == TRUE)
			call LEDControl.On(LEDState_ModeReceive);	
		else
			call LEDControl.Off(LEDState_ModeReceive);	
		toggle = !toggle; 
		
		pack = *((Package*)payload);
		
		pack.rssi = (call CC2420Packet.getRssi(msg))-45; //The offset is about -45 due to the specification.
		
//		if(packagePtr->arq == TRUE)
//			toggle = toggle;// ARQ received
//		else
//			toggle = toggle;// data received
		call Data.Stream(&pack);
		
		return msg;
	}
}